{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">原商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id" lay-search="">
                                <option value="0"></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}">{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}
                                </option>
                                {else/}
                                <option value="{$t.id}">{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}
                                </option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="new_merchant_id" lay-search="">
                                <option value="0"></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}">{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}
                                </option>
                                {else/}
                                <option value="{$t.id}">{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}
                                </option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">入离场：</label>
                        <div class="layui-input-inline">
                            <select name="in_type">
                                <option value="">请选择</option>
                                <option value="1">入场</option>
                                <option value="2">离场</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="overflow: inherit;">表编号：</label>
                        <div class="layui-input-inline">
                            <input name="pointId" class="layui-input" id="pointId" value="" type="text"
                                   placeholder="表编号">
                        </div>
                    </div>
                    <!--                    <div class="layui-inline">-->
                    <!--                        <label class="layui-form-label">请选择日期</label>-->
                    <!--                        <div class="layui-inline" id="test6">-->
                    <!--                            <div class="layui-input-inline">-->
                    <!--                                <input type="text" autocomplete="off" name="startDate" id="startDate" class="layui-input" placeholder="开始日期">-->
                    <!--                            </div>-->
                    <!--                            &lt;!&ndash;                            <div class="layui-form-mid">-</div>&ndash;&gt;-->
                    <!--                            &lt;!&ndash;                            <div class="layui-input-inline">&ndash;&gt;-->
                    <!--                            &lt;!&ndash;                                <input type="text" autocomplete="off"  name="endDate" id="endDate" class="layui-input" placeholder="结束日期">&ndash;&gt;-->
                    <!--                            &lt;!&ndash;                            </div>&ndash;&gt;-->
                    <!--                        </div>-->
                    <!--                    </div>-->
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search"
                                lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i
                                class="layui-icon layui-icon-refresh"></i>{:__('Reset')}
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
        <!--        <button type="button" id="export" class="layui-btn {:node('ExportCenter/export')} layui-btn-sm">导出模板-->
        <!--        </button>-->
        <!--        <button type="button" id="import" class="layui-btn  layui-btn-sm">导入</button>-->
        <!-- <button type="button" id="import" class="layui-btn {:node('ExportCenter/import')} layui-btn-sm">导入</button> -->
    </div>
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('MerchantReadingLog/del')}"
       data-title="删除"
       lay-event="del"><i class="layui-icon "></i></a>
</script>

<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'opTable', 'laydate', 'upload'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        var laydate = layui.laydate;
        var upload = layui.upload;
        form.render();
        laydate.render({
            elem: '#startDate'
            , type: 'month',
            trigger: 'click'
        });
        // laydate.render({
        //     elem: '#endDate'
        //     ,type: 'month',
        //     trigger: 'click'
        // });

        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            where: {info_type: 2},
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: [''],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {title: '', type: 'checkbox', fixed: true},
                // { title: 'ID', field: 'id'},
                {
                    title: '原商户', field: 'merchant_sn', templet: function (item) {
                        if (item.oldmchants == ''||item.oldmchants==null) {
                            return '原表无关联商户';
                        } else {
                            if (item.oldmchants.name == '-' || item.oldmchants.name == '') {
                                return item.oldmchants.company
                            } else {
                                return item.oldmchants.name
                            }
                        }

                    }
                },

                {
                    title: '新商户', field: 'merchant_sn', templet: function (item) {
                        if (item.newmerchants == ''||item.newmerchants==null) {
                            return '原表无关联商户';
                        } else {
                            if (item.newmerchants.name == '-' || item.newmerchants.name == '') {
                                return item.newmerchants.company
                            } else {
                                return item.newmerchants.name
                            }
                        }
                    }
                },
                {
                    title: '入离场', field: 'merchant_sn', templet: function (item) {
                        if (item.in_type == 1) {
                            return '入场'
                        } else {
                            return '离场'
                        }
                    }
                },
                // { title: '商户ID', field: 'userId'},
                {title: '表编号', field: 'pointId'},
                {
                    title: '设备类型', field: 'type', width: 100, templet: function (item) {
                        if (item.type == 1) {
                            return '智能电表';
                        } else if (item.type == 2) {
                            return '智能水表'
                        } else if (item.type == 3) {
                            return '普通电表'
                        } else if (item.type == 4) {
                            return '普通水表'
                        }
                        return item.type == 1 ? '电表' : '水表'
                    }
                },
                {title: '峰值', field: 'fengpower'},
                {title: '谷值', field: 'gupower'},
                {title: '平值', field: 'pingpower'},
                {title: '单一', field: 'sole'},
                {title: '月份', field: 'dateTime'},

                {
                    title: '创建时间', field: 'create_time', templet: function (item) {
                        if (item.create_time == '' || item.create_time == null) {
                            return '暂无';
                        } else {
                            return layui.util.toDateString((item.create_time) * 1000)
                        }

                    }
                },
                {
                    title: '商户是否确认', field: 'merchant_sn', templet: function (item) {
                        if (item.is_read == 1) {
                            return '已确认'
                        } else {
                            return '未确认'
                        }
                    }
                },
                // {templet: '#operationTpl', width:50,fixed:'right', align: 'center', title: '操作'}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });
        //导出
        $('#export').on('click', function () {
            var url = "{:url('export')}";
            window.open(url);
        });
        //导入
        upload.render({
            elem: '#import',
            url: "{:url('import')}",
            accept: 'file', //普通文件
            multiple: false,
            exts: 'xlsx|xls', // 限制文件类型为 xlsx或xls
            done: function (data) {  // 成功的回调函数
                console.log(data)
                if (data.code == 1) {
                    alert(data.msg);
                }
            }
            , error: function (index, upload) {  // 失败的回调函数

            }
        });
        //导出时阻止页面刷新
        $(".layui-form").submit(function (e) {
            e.preventDefault();
        })


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "detail") {
                lucky.CreateOpenForm("查看", "{:url('detail')}?merchant_id=" + data.merchant_id + "&type=" + data.electrity_type + "&settlement_time=" + data.settlement_time + '&merchant_sn=' + data.merchant.merchant_sn);
                return false;
            } else if (layEvent === "del") {
                lucky.FormatData(_id, "{:url('del')}");
            } else if (layEvent === "edit") {
                lucky.CreateOpenForm("审核提交", "{:url('common/costEdit')}?id=" + _id);
                return false;
            } else if (layEvent === "print") {
                lucky.CreateOpenForm("打印", "{:url('common/costPrint')}?id=" + _id, '85%');
                return false;
            } else if (layEvent === "invoice") {
                var datas = {};
                datas.id = _id;   //  购买数量
                $.ajax({
                    url: "{:url('invoice')}",
                    type: "post",
                    data: datas,
                    dataType: "json",
                    success: function (data) {
                        layer.msg(data.msg, {icon: 15, time: 1000, shade: 0.3});
                        window.location.reload();
                    }
                });
                return false;
            }
        });
        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                lucky.CreateOpenForm("生成费用单", "{:url('add')}");
                return false;
                // adminAdd
            } else if (obj.event === "adminAdd") {
                lucky.CreateOpenForm("添加人工缴费用", "{:url('adminAdd')}");
                return false;
            } else if (obj.event === "close") {
                opTables.closeAll();
            } else if (obj.event === "open") {
                opTables.openAll();
            } else if (obj.event === "detail") {
                lucky.CreateOpenForm("订单详情", "{:url('detail')}");
                return false;
            } else if (obj.event === "reload") {
                lucky.CreateReload();
            } else if (obj.event === "del") {
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", {time: 1500});
                    return false;
                }
                lucky.FormatData(id, "{:url('del')}");
                return false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}
